package com.zmn.oms.services.impl.chan;

import com.alibaba.fastjson.JSON;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.mq.constant.MqTagConsts;
import com.zmn.manager.mq.constant.MqTopicConsts;
import com.zmn.manager.mq.interfaces.ZmnMQSender;
import com.zmn.oms.manager.utils.OmsMqTagConsts;
import com.zmn.oms.model.entity.chan.FacadeMessageEvent;
import com.zmn.oms.services.interfaces.chan.FacadeSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 类描述：
 *
 * @author LiangHailong
 * @date 2021/01/01 15:43
 */
@Slf4j
@Service("facadeSyncService")
public class FacadeSyncServiceImpl implements FacadeSyncService {

    @Resource
    private ZmnMQSender zmnMQSender;

    @Override
    public void sendFacadeMessageEventSync(FacadeMessageEvent facadeMessageEvent) {
        String key = "chan_facade_msg_evt_" + StringUtil.getRandomStringAndNumber3(12);
        facadeMessageEvent.setMqMsgKey(key);
        String json = JSON.toJSONString(facadeMessageEvent);
        log.info("[channel-facade-msg-evt] send event:{} key:{}", json, key);
        zmnMQSender.send(MqTopicConsts.ZMN_TOPIC_OMS, OmsMqTagConsts.CHAN_FACADE_MSG_EVENT_TAG, key, json);
    }
}
